package cn.lut.springboot.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import sun.awt.SunHints;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import java.util.Arrays;

/**
 * @user:dell
 * @date:2021年01月05 10:14
 */
@Controller
public class TestController {
    @Autowired
    private ServletContext servletContext;
    @RequestMapping(value ="/test/thymeleaf" )
    public String test1(ModelMap modelMap, HttpSession session){
//        1.将测试数据存入请求域
        modelMap.addAttribute("attrNameRequestScope","attrValueRequestScope");
//        2.将测试数据存入session域中
        session.setAttribute("attrNameSessionScope","attrValueSessionScope");
//        3.将测试数据存入应用域
        servletContext.setAttribute("attrNameAppScope","attrValueAppScope");
//        4.测试遍历
        modelMap.addAttribute("list", Arrays.asList("AAAAA","BBBBBBB","CCCCCCCC"));

        return "hello";
    }
}
